import { Component, OnInit } from '@angular/core';
import { ChatService } from 'src/app/services/chat.service';
import { ChatBase } from 'src/app/classes/chat-base';
import { Title } from '@angular/platform-browser';

@Component({
  selector: 'app-chating',
  templateUrl: './chating.component.html',
  styleUrls: ['./chating.component.less']
})
export class ChatingComponent implements OnInit {
  chat: ChatBase;

  message: string;

  constructor(private chatService:ChatService,private titleService: Title) { }

  ngOnInit() {
    this.chat = this.chatService.chat;
    this.titleService.setTitle(this.chat.name);
  }

  sendMsg(){
    this.chat.msgs.push({id:0, fromUser: this.chatService.user, toChat: this.chat, type: 'simple', state: 'sending', message: this.message});
    this.message = '';
  }
}
